package com.micro.balance;

import java.util.ArrayList;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import org.springframework.stereotype.Component;

/**
 * 随机算法
 * @author Administrator
 *
 */
@Component("random")
public class RandomLoadBalance extends AbstractLoadBalance{

	@Override
	protected String doSelect(Map<String,Integer> map){
		ArrayList<String> lists = new ArrayList<String>();
		Set<String> sets=map.keySet();
	    lists.addAll(sets);
	    
		int len=lists.size();
        Random random=new Random();
        int index=random.nextInt(len);
        
        return lists.get(index);
	}

}
